/**
 * 就是在处理筛选路由，然后动态添加进路由表的逻辑
 */
// import homeRoutes from "../../router/homeRoutes/homeRoutes"
import router from "../../router"
import { filterRouter } from "../../utils/filterRoute"

const state = {
    filterRoute: []
}

const mutations = {
    setArr(state, data) {
        state.filterRoute = data;
    }
}

const actions = {
    getRouters({ commit }, userInfo) {
        const newuserInfo = userInfo || sessionStorage.getItem("name");
        const res = filterRouter(router, newuserInfo);
        router.addRoutes(res);
        commit('setArr', res);

        router.push(res[0].path).catch(err => err)
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}